<?php

namespace app\admin\model;

use think\Model;


class OrderReviews extends Model
{

    

    

    // 表名
    protected $table = 'order_reviews';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_anonymous_text',
        'reply_time_text'
    ];
    

    
    public function getIsAnonymousList()
    {
        return ['0' => __('Is_anonymous 0'), '1' => __('Is_anonymous 1')];
    }


    public function getIsAnonymousTextAttr($value, $data)
    {
        $value = $value ?: ($data['is_anonymous'] ?? '');
        $list = $this->getIsAnonymousList();
        return $list[$value] ?? '';
    }


    public function getReplyTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['reply_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setReplyTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function goods()
    {
        return $this->belongsTo('Goods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function distributor()
    {
        return $this->belongsTo('User', 'distributor_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function verifier()
    {
        return $this->belongsTo('User', 'verifier_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
